#pragma once 

#include "ViewPortUpdate.h"

class ViewPortUpdateVertical : public ViewPortUpdate {
public:
	ViewPortUpdateVertical(ViewPortData* viewport) : ViewPortUpdate(viewport) {}

	virtual void update(double mapwidth, double mapheight) {
		// Check if main player go to half of viewport.
		// then make viewport move follow main player.
		// exception: when reach the end of map , not move viewport follow.
		if (_viewport->targetRect->Y  >= _viewport->Y + _viewport->Height/2) {
			if (_viewport->getTop() <= mapheight && _viewport->targetRect->Vy > 0) {
				_viewport->Y += _viewport->targetRect->Vy;
			}
		} else {
			if (_viewport->targetRect->X < _viewport->X + 50) {
				_viewport->targetRect->X = _viewport->X + 50;
			}
			if (_viewport->targetRect->X > _viewport->X + _viewport->Width - 50) {
				_viewport->targetRect->X = _viewport->X + _viewport->Width - 50;
			}
		}
		_viewport->CurView->X = _viewport->targetRect->X;
		_viewport->CurView->Y = _viewport->targetRect->Y;;
	}
};